package com.ysd.servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.ysd.dao.impl.CompenyDaoImpl;
import com.ysd.entity.Compeny;
import com.ysd.util.BaseServlet;
import com.ysd.util.Result;

public class AdminCompenyServlet extends BaseServlet {
	/**
	 * 查询公司表的所有数据
	 * localhost:8080/shangcheng1/adminCompeny?reqName=selCompeny
	 */
	public void selCompeny(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		CompenyDaoImpl cDao = new CompenyDaoImpl();
		 Compeny com = cDao.getCompeny();
		
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();//创建out对象
		
		Gson gson = new Gson();//创建gson对象
		
		String res = gson.toJson(com);//将fcList转化为json对象
		out.print(res);//响应
		
		out.flush();
		out.close();
	}

	
	
	/**
	 * localhost:8080/shangcheng1/adminCompeny?reqName=updateCompenyById
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void updateCompenyById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();//创建out对象
		
		CompenyDaoImpl comDao = new CompenyDaoImpl();
		
		String logo = request.getParameter("logo");
		String url = request.getParameter("url");
		String theme = request.getParameter("theme");
		String introduce = request.getParameter("introduce");
		String phone = request.getParameter("phone");
		String email = request.getParameter("email");
		String adress = request.getParameter("adress");
		String culture = request.getParameter("culture");
		
		Compeny com =  new Compeny(logo, url, theme, introduce, phone, email, adress, culture);
		int n = comDao.updateCompany(com);
		
		if (n > 0) {
			out.print(Result.toClient(true, "修改成功", ""));
		} else {
			out.print(Result.toClient(false, "修改失败", ""));
		}
		
		out.flush();
		out.close();
	}
	
}
